﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using SW.YUNCMS.Configuration;
using SW.YUNCMS.Web;

namespace SW.YUNCMS.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class YUNCMSDbContextFactory : IDesignTimeDbContextFactory<YUNCMSDbContext>
    {
        public YUNCMSDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<YUNCMSDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            YUNCMSDbContextConfigurer.Configure(builder, configuration.GetConnectionString(YUNCMSConsts.ConnectionStringName));

            return new YUNCMSDbContext(builder.Options);
        }
    }
}
